package com.zl.init;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import com.zl.framework.util.PropConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @Author: yax
 * @Date: 2020/11/20 16:13
 */
@Component
public class ContainerSuccessListener implements ApplicationListener<ContextRefreshedEvent> {
    private static Logger logger = LoggerFactory.getLogger(ContainerSuccessListener.class);
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        PropConfig propConfig = PropConfig.loadConfig("setting-web.properties");
        String level=propConfig.getConfigString("jdbc.sql.level");
        if(level!=null&&"debug".equalsIgnoreCase(level)){
            logger.info("--------------------初始化sql日志级别为debug-----------------");
            LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
            ch.qos.logback.classic.Logger vLogger = loggerContext.getLogger("com.zl.framework.dal.client.support.executor.MappedSqlExecutor");
            vLogger.setLevel(Level.DEBUG);
        }
    }
}
